package com.gitee.hljdrl.dsbridge.basis;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Keep;

import com.ffsky.logger.L;

@Keep
public abstract class BasePresenter implements ViewPresenter {

    protected String TAG = getClass().getSimpleName();
    private Activity activity;
    private Bundle mBundle;
    private View mView;

    @Override
    public Activity getActivity() {
        return activity;
    }

    protected Bundle getBundle() {
        if (mBundle == null) {
            if (activity != null) {
                return activity.getIntent().getExtras();
            }
            L.i(TAG,"getBundle NULL !");
            return new Bundle();
        }
        return mBundle;
    }

    public View getView() {
        return mView;
    }

    @Override
    public final <T extends View> T findViewById(int id) {
        if (mView != null) {
            return mView.findViewById(id);
        }
        return activity.findViewById(id);
    }

    @Override
    public void onCreate(Activity activity) {
        L.i(TAG, "onCreate(Activity...)");
        this.activity = activity;
        initView();
        initEvent();
    }

    @Override
    public void onCreate(Activity activity, View view, Bundle bundle) {
        L.i(TAG, "onCreate(Activity...,View...,Bundle...)");
        this.activity = activity;
        this.mView = view;
        this.mBundle = bundle;
        initView();
        initEvent();
    }

    @Override
    public void onResume() {
        L.i(TAG, "onResume");
    }

    @Override
    public void onPause() {
        L.i(TAG, "onPause");
    }

    @Override
    public void onDestroy() {
        L.i(TAG, "onDestroy");
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        L.i(TAG, "onActivityResult requestCode=", requestCode, " resultCode=", resultCode);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        L.i(TAG, "onConfigurationChanged");
    }

    @Override
    public boolean onBackPressed() {
        L.i(TAG, "onBackPressed");
        return false;
    }
}
